package com.mzk.qBittorrentPush.util;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

/**
 * @ ProjectName: qBittorrentPush
 * @ Author     ：miaozhenkai
 * @ Date       ：Created in 2020/10/11 0:23
 * @ Description：Base64Utils
 * @ Modified By：
 * @ Version:     1.0
 */
public class Base64Utils {


    /**
     * 编码
     *
     * @param s
     * @return
     */
    public static String encoderBase64(String s) {
        String asB64 = null;
        try {
            asB64 = Base64.getEncoder().encodeToString(s.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(asB64);
        return asB64;
    }

    /**
     * 解码
     *
     * @param s
     * @return
     */
    public static String decoderBase64(String s) {
        byte[] asBytes = Base64.getDecoder().decode(s);
        String decoderString = "";
        try {
            decoderString = new String(asBytes, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(decoderString);
        return decoderString;
    }


}
